package com.orangelife.utils;

import java.util.List;
import java.util.Map;

import com.orangelife.exception.AppBizException;

public class SplicingUtils {

	/***
	 * 拼接 列表信息
	 * 
	 * @param mainList
	 *            列表信息
	 * @param subList
	 *            返回 请求信息
	 * @param mainID
	 *            主要ID
	 * @param subID
	 *            返回ID
	 * @param connValue
	 *            要拼接的ekey
	 * @return
	 */
	public static List<Map<String, Object>> connoList(
			List<Map<String, Object>> mainList,
			List<Map<String, Object>> subList, String mainID, String subID,
			Map<String, String> connValue) {
		try {
			if (connValue == null || connValue.size() <= 0) {
				throw new AppBizException(2, "亲，匹配信息不可为空");
			}
			if ((mainList != null && mainList.size() > 0) && subList != null
					&& subList.size() > 0) {
				for (Map<String, Object> mainMap : mainList) {
					for (Map<String, Object> subMap : subList) {
						if (mainMap.get(mainID) != null
								&& subMap.get(subID) != null) {
							if (mainMap.get(mainID).equals(subMap.get(subID))) {
								for (Map.Entry<String, String> entry : connValue
										.entrySet()) {
									mainMap.put(entry.getKey(),
											subMap.get(entry.getValue()));
								}
							}
						}
					}
				}
			}
		} catch (AppBizException e) {
			// TODO: handle exception
		}

		return mainList;
	}
}
